home *** CD-ROM | disk | FTP | other *** search
/ Run Magazine ReRun 1986 March & April / rerun-1986-03-04.d64 / define macros (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  2KB  |  76 lines

  1. 10 rem define macros by robert rockefeller
  2. 90 dim flag%(51) : rem flag array indicates if a certain macro is defined
  3. 100 dim macro$(51) : rem holds macro strings
  4. 110 m1$="this character has been used. would you like to select another (y/n)?"
  5. 120 m2$="how many characters will be in the"
  6. 130 m2$=m2$+"      macro string represented by this        character ? "
  7. 140 a=780 : x=781 : y=782 : rem sys registers
  8. 180 rem select macro character
  9. 200 print"[147]select a macro character."
  10. 210 gosub 1130
  11. 230 if a$<>"*" then 300
  12. 240 print"which macro definition do you wish to   cancel ?"
  13. 250 gosub 1130
  14. 260 if a$="*" then 240
  15. 270 flag%(macnum)=0 : rem cancel def
  16. 280 goto 470
  17. 300 if flag%(macnum)<>0 then print m1$ : input b$ : if left$(b$,1)="y" then 200
  18. 320 flag%(macnum)=1
  19. 330 macro$(macnum)=""
  20. 370 rem define macro string
  21. 390 printm2$: input count
  22. 400 if count>20 then 390
  23. 420 for loop=1 to count
  24. 430 input"decimal value ";dec
  25. 440 macro$(macnum)=macro$(macnum)+chr$(dec)
  26. 450 next loop
  27. 470 input"finished all definitions (y/n) ";b$
  28. 480 if left$(b$,1)<>"y" then 200
  29. 520 rem create macro table
  30. 540 ptr=4*4096 : rem create macro table at this address
  31. 550 for entry=0 to 51
  32. 560 if flag%(entry)=0 then 750
  33. 580 rem convert to reversed screen code value
  34. 590 if entry<26 then code=entry+1+128
  35. 600 if entry>25 then code= entry+39+128
  36. 620 poke ptr,code : rem 1st byte of 1 macro entry is screen code value
  37. 630 ptr=ptr+1 : rem next table byte
  38. 650 poke ptr,len(macro$(entry))+2 : rem 2nd byte is entry length
  39. 660 ptr=ptr+1 : rem next table byte
  40. 680 for iloop=1 to len(macro$(entry)) : rem rest of 1 entry is macro string
  41. 690 poke ptr,asc(mid$(macro$(entry),iloop,1))
  42. 700 ptr=ptr+1
  43. 710 next iloop
  44. 730 if ptr=>4*4096+500 then print"macro table too large !!!" : stop
  45. 750 next entry
  46. 790 rem save macro table
  47. 820 print"[147]8 - disk
  48. 830 [153]"9 - disk
  49. 840 input"save to device number ";dev
  50. 850 if dev<>1 and dev<>8 and dev<>9 then 840
  51. 870 rem use the kernal setlfs
  52. 880 poke a,0 : poke x,dev : poke y,0
  53. 890 sys 65466
  54. 910 rem setup filename
  55. 920 b$="runscript macros"
  56. 930 for loop=1 to len(b$)
  57. 940 poke 849+loop,asc(mid$(b$,loop,1))
  58. 950 next loop
  59. 970 rem use kernal setnam
  60. 980 poke a,len(b$) : poke x,850and255 : poke y,850/256
  61. 990 sys 65469
  62. 1010 rem use kernal save
  63. 1020 poke 253,0 : poke 254,4*16
  64. 1030 poke a,253 : poke x,ptrand255 : poke y,ptr/256
  65. 1040 sys 65496
  66. 1070 end
  67. 1110 rem input subroutine
  68. 1130 input a$ : a$=left$(a$,1)
  69. 1150 if a$="*" then return
  70. 1160 if a$<"a" then 1130
  71. 1170 if a$>"[218]" then 1130
  72. 1180 if a$>"z" and a$<"[193]" then 1130
  73. 1200 if a$<="z" then macnum=asc(a$)-65
  74. 1210 if a$>="[193]" then macnum=asc(a$)-167
  75. 1230 return
  76.